import Vue from 'vue'
import Router from 'vue-router'
import {mode,routerBase} from "../config/env"
Vue.use(Router)


//主框 含 header 以及 footer
import main from '@/pages/main/MainView'

// import home from '@/pages/home/home'
// const home = r => require.ensure([], () => r(require('../pages/home/home')), '');

//首页
const home = () => import('../pages/home/home');



//支付
const order_pay = ()=>import('../pages/pay/order_pay');
const pay_success = ()=>import('../pages/pay/pay_success');

//个人中心
const login = ()=>import('../pages/user/login');
const user_center = ()=>import('../pages/user/user_center');


//========================================end==========================================//



const router = new Router({
    mode:mode,
    base:routerBase,
    routes: [
        {
            path: '/main',
            name: 'main',
            component: main,
            children: [
                /*---------------------------首页--------------------------*/
                {
                    path: '/main/home',
                    name: 'home',
                    meta: {title: '首页'},
                    component: home
                },

                /*---------------------------支付--------------------------*/
                {
                    path: '/main/pay/order_pay',
                    name: 'order_pay',
                    meta: {title: '订单支付'},
                    component: order_pay,
                },
                {
                    path: '/main/pay/pay_success',
                    name: 'order_success',
                    meta: {title: '预定成功'},
                    component: pay_success,
                },
                /*---------------------------个人中心--------------------------*/
                {
                    path: '/main/user/user_center',
                    name: 'user_center',
                    meta: {title: '个人中心'},
                    component: user_center
                },
                {
                    path: '/main/user/login',
                    name: 'login',
                    meta: {title: '登录'},
                    component: login,
                }
                /*=================================end======================================*/


            ]
        },
        {
            path: '/',
            name: 'default',
            redirect: {
                name: 'home'
            }
        },
        {
            path: '*',
            name: '404',
            redirect: {
                name: 'home'
            }
        }
    ]
})


router.afterEach((to, from, next) => {
    window.scrollTo(0,0);
    if (to.meta.title) document.title = to.meta.title;
})
export default router;
